package com.xiaohong.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.user.pojo.UsernameList;
import com.xiaohong.user.service.ChatUsernameListService;
import entity.Result;
import entity.StatusCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "ChatUsernameList接口文档")
@RestController
@RequestMapping("/chatUsernameList")
@CrossOrigin
public class ChatUsernameListController {

    @Autowired
    private ChatUsernameListService chatUsernameListService;

    /***
     * 分页条件搜索实现ChatUsernameList
     * @param usernameList
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "条件分页查询ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@RequestBody(required = false) @Parameter(name = "ChatUsernameList对象",required = true) UsernameList usernameList, @PathVariable int page, @PathVariable  int size){
        //调用ChatUsernameListService实现分页条件查询ChatUsernameList
        Page pageInfo = chatUsernameListService.findPage(usernameList, page, size);
        return new Result<Page>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 分页搜索实现ChatUsernameList
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @Operation(summary = "分页查询ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用ChatUsernameListService实现分页查询ChatUsernameList
        Page pageInfo = chatUsernameListService.findPage(page, size);
        return new Result<Page>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索ChatUsernameList数据
     * @param usernameList
     * @return
     */
    @Operation(summary = "多条件查询ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping(value = "/search" )
    public Result<List<UsernameList>> findList(@RequestBody(required = false) @Parameter(name = "ChatUsernameList对象",required = true) UsernameList usernameList){
        //调用ChatUsernameListService实现条件查询ChatUsernameList
        List<UsernameList> list = chatUsernameListService.findList(usernameList);
        return new Result<List<UsernameList>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据Id删除chatUsernameList数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID删除ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "删除对象ID", required = true)
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用ChatUsernameListService实现根据ID删除
        chatUsernameListService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 根据ID修改ChatUsernameList数据
     * @param usernameList
     * @return
     */
    @Operation(summary = "根据ID修改ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PutMapping
    public Result update(@RequestBody @Parameter(name = "ChatUsernameList对象",required = true) UsernameList usernameList){
        //调用ChatUsernameListService实现修改ChatUsernameList
        chatUsernameListService.update(usernameList);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增ChatUsernameList数据
     * @param usernameList
     * @return
     */
    @Operation(summary = "添加ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping
    public Result add(@RequestBody  @Parameter(name = "ChatUsernameList对象",required = true) UsernameList usernameList){
        //调用ChatUsernameListService实现添加ChatUsernameList
        chatUsernameListService.add(usernameList);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询ChatUsernameList数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID查询ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "查询对象ID", required = true)
    @GetMapping("/{id}")
    public Result<UsernameList> findById(@PathVariable Long id){
        //调用ChatUsernameListService实现根据ID查询ChatUsernameList
        UsernameList usernameList = chatUsernameListService.findById(id);
        return new Result<UsernameList>(true,StatusCode.OK,"查询成功", usernameList);
    }

    /***
     * 查询ChatUsernameList全部数据
     * @return
     */
    @Operation(summary = "查询所有ChatUsernameList",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping
    public Result<List<UsernameList>> findAll(){
        //调用ChatUsernameListService实现查询所有ChatUsernameList
        List<UsernameList> list = chatUsernameListService.findAll();
        return new Result<List<UsernameList>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
